Add opt-in extended activity tracking with activity_metrics entity#1467
Conversation
Attach quantitative activity metrics (mouse distance, scroll distance, key presses, clicks, touches) to page_ping events when extendedActivityTracking is enabled. Reuses existing DOM event handlers with zero overhead when the feature is off. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “extended activity tracking” mode to the Snowplow Browser Tracker so page pings can include quantitative interaction metrics (mouse distance, scroll distance, key presses, clicks, touches) via an activity_metrics context entity and via activity callback data.
Changes:
- Introduces
ActivityMetricstype andextendedActivityTrackingconfiguration flag, and wires metric accumulation into activity/scroll handlers. - Attaches an
activity_metricsself-describing entity to page ping contexts (and surfaces metrics onActivityCallbackData). - Adds Jest coverage validating accumulation, reset behavior, and callback population.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| trackers/browser-tracker/src/api.ts | Re-exports ActivityMetrics from the public browser-tracker API surface. |
| libraries/browser-tracker-core/src/tracker/types.ts | Adds ActivityMetrics + extendedActivityTracking option and exposes metrics on callback data. |
| libraries/browser-tracker-core/src/tracker/schemata.ts | Adds ACTIVITY_METRICS_SCHEMA constant. |
| libraries/browser-tracker-core/src/tracker/index.ts | Implements metric accumulation, entity attachment, and lifecycle resets for extended tracking. |
| libraries/browser-tracker-core/test/tracker/extended_activity_tracking.test.ts | Adds tests for metric accumulation/reset and callback exposure. |
| api-docs/docs/browser-tracker/browser-tracker.api.md | Updates generated API docs for new types/config fields. |
| common/changes/@snowplow/browser-tracker/feature-extended-activity-tracking_2026-04-06-13-19.json | Adds change entry for browser-tracker package. |
| common/changes/@snowplow/browser-tracker-core/feature-extended-activity-tracking_2026-04-06-13-19.json | Adds change entry for browser-tracker-core package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This looks good, but could you please add something closer to an integration test in Here is something that AI suggested, but whatever gets us closer to an integration test (probably extending the e2e browser tests we have would be too much complicated): it('attaches activity_metrics entity to page ping payload when using callback with extendedActivityTracking', async () => {
const ACTIVITY_METRICS_SCHEMA = 'iglu:com.snowplowanalytics.snowplow/activity_metrics/jsonschema/1-0-0';
const state = new SharedState();
const t =
addTracker('sp8', 'sp8', '', '', state, {
stateStorageStrategy: 'cookie',
encodeBase64: false,
customFetch,
eventStore,
}) ?? fail('Failed to create tracker');
t.enableActivityTrackingCallback({
minimumVisitLength: 0,
heartbeatDelay: 10,
extendedActivityTracking: true,
callback: () => {}, // no-op — we're testing the payload, not the callback data
});
t.trackPageView();
// advance 1s, fire two clicks, then complete the heartbeat window
jest.advanceTimersByTime(1000);
document.dispatchEvent(new MouseEvent('click'));
document.dispatchEvent(new MouseEvent('click'));
jest.advanceTimersByTime(9000);
const events = await eventStore.getAllPayloads();
const pings = getPPEvents(events);
expect(F.size(pings)).toBe(1);
const entities = JSON.parse(pings[0].co as string).data as Array<{ schema: string; data: any }>;
const metricsEntity = entities.find((e) => e.schema === ACTIVITY_METRICS_SCHEMA);
expect(metricsEntity).toBeDefined();
expect(metricsEntity!.data.clicks).toBe(2);
}); |
Matus Tomlein (matus-tomlein)
left a comment
There was a problem hiding this comment.
LGTM!
89c42c6
into
release/4.8.0
…1467) * Add opt-in extended activity tracking with activity_metrics entity Attach quantitative activity metrics (mouse distance, scroll distance, key presses, clicks, touches) to page_ping events when extendedActivityTracking is enabled. Reuses existing DOM event handlers with zero overhead when the feature is off. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add change files * Add API extractor changes * Address review feedback --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Attach quantitative activity metrics (mouse distance, scroll distance, key presses, clicks, touches) to page_ping events when extendedActivityTracking is enabled. Reuses existing DOM event handlers with zero overhead when the feature is off.